package com.sicheng.hello.controller;

import com.baomidou.kaptcha.Kaptcha;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
/**
 * @author zsc
 * @version 1.0
 * @date 2021/10/9 21:03
 */
@CrossOrigin
@RestController
public class CodeController {

    @Resource
    private Kaptcha kaptcha;

    @GetMapping("/render")
    public void render() {
        kaptcha.render();
    }

    @PostMapping("/valid")
    public void validDefaultTime(@RequestParam String code) {
        //default timeout 900 seconds
        kaptcha.validate(code);
    }

    @PostMapping("/validTime")
    public void validCustomTime(@RequestParam String code) {
        kaptcha.validate(code, 60);
    }
}
